<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

/**
 * 无需token和登录
 */
Route::get('openid', 'LoginController@openid'); //code缓存openid
Route::get('token', 'TokenController@getToken'); //获取token
Route::get('selectCity', 'LocationController@selectCity')->name('roots.selectCity'); //我的地理位置选择
Route::get('cityAreas', 'LocationController@getCityAreas'); //获取城市下城区和商圈

//微信
Route::any('wechat/notify/pay', 'WechatNotifyController@notify'); //微信支付通知
Route::any('wechat/notify/refund', 'WechatNotifyController@refundNotify'); //微信退款通知



/**
 * api 站点
 * 无需登录
 */
Route::group([
    'middleware' => ['minitoken', 'UserLocationCityCheck', \App\Http\Middleware\Distribution::class],
], function () {
    Route::post('verify', 'LoginController@verify'); //获取验证码
    Route::post('login', 'LoginController@login'); //登陆
    Route::get('products', 'ProductsController@index')->name('products'); //首页
    Route::get('plist', 'ProductController@list')->name('plist'); //产品列表页
    Route::get('product/{productId}', 'ProductController@show')->name('product.show'); //产品详情
    Route::get('stock', 'StockController@index'); //
    Route::get('stock/lastServiceAbleDateTime/{productSkuId}', 'StockController@lastServiceAbleDateTime');
    Route::get('convertiblecard/list', 'ConvertibleCardController@index'); //权益卡列表
    Route::get('convertiblecard/detail', 'ConvertibleCardController@show'); //权益卡详情
    Route::get('protocol/{name}', 'ProtocolController@index'); //协议
});

/**
 * api 站点
 * 需登录
 */
Route::group([
    'middleware' => ['minitoken', 'UserLocationCityCheck', \App\Http\Middleware\LoginCheck::class, \App\Http\Middleware\Distribution::class],
], function () {
    Route::post('setCity', 'LocationController@setCity')->name('roots.setCity'); //设置我的地理位置

    Route::get('usercenter', 'UserCenterController@index'); //用户中心

    Route::get('wechat/payment/{tradeNo}', 'WechatPaymentController@pay'); //微信支付通知

    Route::get('myconvertiblecard/list', 'UserConvertibleCardController@index'); //我的权益卡列表
    Route::get('myconvertiblecard/records', 'UserConvertibleCardController@records'); //我的权益卡列表

    Route::get('detailsRewards', 'UserCenterController@detailsRewards'); //用户赏金列表
    Route::post('user/wechat/{openid}', 'UserCenterController@updateWechat'); //用户微信信息更新 头像、昵称、性别、城市等

    Route::get('user/coupon', 'UserCouponController@index')->name('user.coupon.index'); //用户优惠券列表

    Route::get('user/balance', 'UserBalanceController@index')->name('user.balance.index');
    Route::get('user/balance/record', 'UserBalanceController@record')->name('user.balance.record');
    Route::get('user/poster', 'UserCenterController@poster')->name('user.poster'); //海报

    Route::post('order', 'OrderController@store')->name('order.store'); //新建订单

    Route::get('wechat/payment/{tradeNo}', 'WechatPaymentController@pay'); //微信支付

    Route::get('cart', 'CartController@index')->name('cart.index'); //购物车页面
    Route::post('cart', 'CartController@store')->name('cart.store'); //添加购物车

    //评论
    Route::get('user/review/{order}', 'ReviewController@comment')->name('review.create');//评价页面
    Route::post('user/review', 'ReviewController@doComment')->name('review.store');

    Route::get('user/order', 'UserOrderController@index')->name('user.order.index'); //用户订单列表
    Route::get('user/order/{orderId}', 'UserOrderController@show')->name('user.order.show'); //用户订单详情
    Route::post('user/order/{orderId}/cancel', 'UserOrderController@cancel')->name('user.order.cancel');
    Route::post('user/order/{orderId}/refund', 'UserOrderController@refund')->name('user.order.refund');
    Route::post('user/order/{orderId}/refundCancel', 'UserOrderController@refundCancel')->name('user.order.refundCancel');
    Route::get('user/addresses', 'UserAddressesController@index'); //我的用户地址列表
    Route::post('user/address/store', 'UserAddressesController@store'); //新增用户地址入库
    Route::get('user/address/productFilter', 'UserAddressesController@productFilter'); //通过产品过滤用户地址
    Route::post('user/address/update', 'UserAddressesController@update'); //用户地址更新
    Route::post('user/address/delete', 'UserAddressesController@destroy'); //地址删除
    Route::get('user/address/info', 'UserAddressesController@info'); //单条地址

    Route::post('convertiblecard/purchase', 'ConvertibleCardController@purchase'); // 购买
});
